<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<meta name="renderer" content="webkit|ie-comp|ie-stand" />
<meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE">
<title>学生-课程-成绩</title>
<%@ include file="/common/commonLib.jsp"%>
<link rel="stylesheet" type="text/css" href="<c:url value='/css/courseScore-stu.css'/>"/>
<link rel="stylesheet" type="text/css" href="<c:url value='/css/common-main.css'/>"/>
<script src="<c:url value='/js/courseScore-stu.js'/>" type="text/javascript" charset="utf-8"></script>
</head>
<body>
	<%@include file="/common/header.jsp"%>
	<%@include file="classHeader.jsp"%>
	<div class="container-fluid main">
		<div class="row">
			<!--课堂、任务、资源、成绩、评论、答疑-->
			<div class="col-xs-12 col-sm-12 col-md-9">
				<div class="row">
					<!--课堂、任务、资源、成绩、评论、答疑----内容-->
					<div class="col-md-12">
						<!-- 课堂、任务、资源、成绩、评论、答疑 ---导航 -->
						<%@include file="classNav.jsp"%>
						<!-- 显示成绩 -->
						<div class="course-score-stu">
							<div class="row">
								<!-- 成绩头部 -->
								<div class="col-md-12">
									<div class="score-title">
										 <p>
										 	<span class="label" contenteditable="false">我的成绩</span>
										 </p>
									</div>
								</div>
								<!-- 成绩信息 -->
								<div class="col-md-12">
									<table class="table">
										<thead>
											<tr>
												<th title="平时成绩">平时成绩</th>
												<th title="任务成绩">任务成绩</th>
												<th title="理论考试成绩">理论考试成绩</th>
												<th title="实验成绩">实验成绩</th>
												<th title="总成绩">总成绩</th>
												<th class="show-pc" title="修改时间">修改时间</th>
											</tr>
										</thead>
										<tbody id="gradeDetail">
											
										</tbody>
									</table>
								</div>
								<!-- 成绩详情 -->
								<div class="col-md-12">											
									<div class="score-detail-title">  
									   <span style="white-space:pre;">  </span><span class="line"></span>  
									   <span style="white-space:pre;">  </span><span class="detail-title">成绩详情</span>  
									   <span style="white-space:pre;">  </span><span class="line"></span>  
									</div> 
									<table id="score-detail-info" class="table">
										<thead>
											<tr>														
												<th class="col1">
													<select class="form-control form-control-self" onchange="searchTaskScoreLog()" id="searchTaskScoreByType">
														<option selected = "selected" value="ALL">全部</option>
														<option value="TESTINLESSON">当堂测试</option>
														<option value="HOMEWORK">课后作业</option>
														<option value="LABTEST">实验任务</option>										
													</select>
												</th>
												<th class="col2">任务名</th>												
												<th class="col3">得分</th>
												<th class="col4 show-pc">更新时间</th>
											</tr>
										</thead>
										<tbody id="taskScoreList">
											
										</tbody>
									</table>	
									<div class="page-content" id="scorePage">
										<nav class="pagination" role="navigation">
											<a class="last-page" href="#">
												<i class="fa fa-angle-left"></i>
											</a>
											<span class="page-number">...</span>
											<a class="next-page" href="#">
												<i class="fa fa-angle-right"></i>
											</a>
										</nav>
									</div>							
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
			<!--教师、助教信息，课程简介-->
			<div class="col-xs-12 col-md-3">
				<%@include file="classRight.jsp"%>
			</div>
		</div>
	</div>
	<%@include file="/common/footer.jsp"%>
</body>
<script>
var data=${data};
$(document).ready(function(){
	if (data.status != "success"){
		alert(data.message);
		return;
	}
	$("#score").css("color","#00b43c");
	initClassView(data.data.classView);
	initGrade(data.data.gradeView);
	initTaskScore();
});

var initGrade = function(view){
	var gradeDetail = $("#gradeDetail");
	gradeDetail.empty();
	var s="<tr>";
	s+="<td title=\""+view.dailyGrade+"\">"+view.dailyGrade+"</td>";
	s+="<td title=\""+view.taskTotalGrade+"\">"+view.taskTotalGrade+"</td>";
	s+="<td title=\""+view.theoryTestGrade+"\">"+view.theoryTestGrade+"</td>";
	s+="<td title=\""+view.labTestGrade+"\">"+view.labTestGrade+"</td>";
	s+="<td title=\""+view.finalTotalGrade+"\">"+view.finalTotalGrade+"</td>";
	s+="<td class=\"show-pc\" title=\""+view.updateDate+"\">"+view.updateDate+"</td>";
	s+="</tr>";
	gradeDetail.append(s);
}

var initTaskScore = function(){
	var json={
			courseId:data.data.classView.courseId,
			pageNo:1
	};
	getTaskScore(json);
}

var getTaskScore = function(json){
	
	$.post(CONTEXT_PATH+"taskGradeListView/ajaxSListData", {
		data : JSON.stringify(json)
	}, function(data) {
		if(data.status=="success"){
			initTaskScoreLog(data.data);
		}else{
			alert(data.message);
		}
	});
}

 var getTaskType = function(type){
		if(type=="ASKINLESSON"){
			return "课堂提问";
		}else if(type=="TESTINLESSON"){
			return "当堂测试";
		}else if(type=="HOMEWORK"){
			 return "课后作业";
		}else if(type=="LABTEST"){
			return "实验任务";
		}else{
			return "个人任务";
		}
	}
 
var initTaskScoreLog = function(data){
	var taskList=$("#taskScoreList");
	taskList.empty();
	var list=data.list;
	if(list.length <= 0){
		var s="<tr><td colspan=\"4\">暂无记录</td></tr>";
		taskList.append(s);
	}else{
		for(var i=0;i<list.length;i++){
			var item=list[i];
			var s="<tr>";
			s+="<td title=\""+getTaskType(item.type)+"\">"+getTaskType(item.type)+"</td>";
			s+="<td title=\""+item.title+"\">"+item.title+"</td>";
			s+="<td title=\""+item.score+"\">"+item.score+"</td>";
			s+="<td class=\"show-pc\" title=\""+item.scoreDate+"\">"+item.scoreDate+"</td>";
			s+="</tr>";
			taskList.append(s);
		}
	}
	
	initPages(data.pageNo,data.allpages);
}

var searchTaskScoreLog = function(){
	var json={
			courseId:data.data.classView.courseId,
			pageNo:1
	};	
	var  type=$("#searchTaskScoreByType  option:selected").val();
	if(type != "ALL"){
		json.type=type;
	}
	getTaskScore(json);
}

var initPages = function(pageNo,allpages){
	
	 var lastPageObj=$("#scorePage .last-page");
		var nextPageObj=$("#scorePage .next-page");
		var pageNumberObj=$("#scorePage .page-number");
		var lastPage=pageNo-1;
		if(lastPage<=0){//设置disableed
			lastPage=1;
		}else{
			 $("#scorePage .last-page").bind("click",{pageNo:lastPage},getPage);
		};
		var nextPage = pageNo+1;
		if(nextPage>allpages){
			nextPage=allpages;
		}else{
			 $("#scorePage .next-page").bind("click",{pageNo:nextPage}, getPage);
		}
		
		/* 需要进一步改进上下这块 */
		if(allpages <= 1){
			$("#scorePage").hide();
		}else{
			pageNumberObj.text("第"+pageNo+"页/共"+allpages+"页");
			$("#scorePage").show();
		}
}
var getPage = function(event){
	var json={
			courseId:data.data.classView.courseId
	};	
	var  type=$("#searchTaskScoreByType  option:selected").val();
	if(type != "ALL"){
		json.type=type;
	}
	json.pageNo=event.data.pageNo;
	getTaskScore(json);
}
</script>
</html>